package portal.manager.servlet;

import java.io.IOException;
import java.net.URL;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.osgi.service.http.HttpContext;

/**
 * 
 * @author Sorrentino
 *
 */
public class HttpContextProxy implements HttpContext {

	private HttpContext delegate;
	
	/**
	 * 
	 * @param ctx
	 */
	public HttpContextProxy( HttpContext ctx ) {
		delegate = ctx;
	}
	
	/**
	 * 
	 */
	public String getMimeType(String arg0) {
		return delegate.getMimeType(arg0);
	}

	/**
	 * 
	 */
	public URL getResource(String name) {
		URL result = delegate.getResource(name);
		
		if( null==result ) {
			try {
				//result = new URL( "file", "", System.getProperty("osgi.syspath") + name );
				result = getClass().getClassLoader().getResource(name);
			} catch (Exception e) {
				//TODO add log
				e.printStackTrace();
			}
		}
		
		return result;
	}

	/**
	 * 
	 */
	public boolean handleSecurity(HttpServletRequest arg0,	HttpServletResponse arg1) throws IOException {
		return delegate.handleSecurity(arg0, arg1);
	}

}
